﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Chowpoo.Sql;

namespace CourseSystem.Core.Entities
{
    [Table(Name = "Posts")]
    public class PostsInfo : IDetach
    {
        public PostsInfo()
        {
            Detach();
        }
        #region Model
        private int _id;
        private int _fid = 0;
        private int _tid = 0;
        private bool _istopic = false;
        private string _title = "";
        private string _message = "";
        private int _postertype = 0;
        private int _posterid = 0;
        private string _postername = "";
        private DateTime _posttime =DateTime.Now;


        private EntityRef<TopicsInfo> _topicsInfo;

        [System.Data.Linq.Mapping.Association(Storage = "_topicsInfo", ThisKey = "Tid", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public TopicsInfo TopicsInfo
        {
            get { return _topicsInfo.Entity; }
            set { _topicsInfo.Entity = value; }
        }


        /// <summary>
        /// 
        /// </summary>
        [Column(IsDbGenerated = true, IsPrimaryKey = true, IsVersion = true)]
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int Fid
        {
            set { _fid = value; }
            get { return _fid; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int Tid
        {
            set { _tid = value; }
            get { return _tid; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public bool IsTopic
        {
            set { _istopic = value; }
            get { return _istopic; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("标题")]
        [Required(ErrorMessage="必须填写")]
        public string Title
        {
            set { _title = value; }
            get { return _title; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("内容")]
        [Required(ErrorMessage = "必须填写")]
        public string Message
        {
            set { _message = value; }
            get { return _message; }
        }
        /// <summary>
        /// 1学生2教师
        /// </summary>
        [Column]
        public int PosterType
        {
            set { _postertype = value; }
            get { return _postertype; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int PosterId
        {
            set { _posterid = value; }
            get { return _posterid; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public string PosterName
        {
            set { _postername = value; }
            get { return _postername; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public DateTime PostTime
        {
            set { _posttime = value; }
            get { return _posttime; }
        }
        #endregion Model

        public void Detach()
        {
            this._topicsInfo = default(EntityRef<TopicsInfo>);
        }
    }
}
